home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / toaiff.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  3KB  |  114 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Convert "arbitrary" sound files to AIFF (Apple and SGI\'s audio format).
  5.  
  6. Input may be compressed.
  7. Uncompressed file type may be AIFF, WAV, VOC, 8SVX, NeXT/Sun, and others.
  8. An exception is raised if the file is not of a recognized type.
  9. Returned filename is either the input filename or a temporary filename;
  10. in the latter case the caller must ensure that it is removed.
  11. Other temporary files used are removed by the function.
  12. '''
  13. from warnings import warnpy3k
  14. warnpy3k('the toaiff module has been removed in Python 3.0', stacklevel = 2)
  15. del warnpy3k
  16. import os
  17. import tempfile
  18. import pipes
  19. import sndhdr
  20. __all__ = [
  21.     'error',
  22.     'toaiff']
  23. table = { }
  24. t = pipes.Template()
  25. t.append('sox -t au - -t aiff -r 8000 -', '--')
  26. table['au'] = t
  27. t = pipes.Template()
  28. t.append('sox -t hcom - -t aiff -r 22050 -', '--')
  29. table['hcom'] = t
  30. t = pipes.Template()
  31. t.append('sox -t voc - -t aiff -r 11025 -', '--')
  32. table['voc'] = t
  33. t = pipes.Template()
  34. t.append('sox -t wav - -t aiff -', '--')
  35. table['wav'] = t
  36. t = pipes.Template()
  37. t.append('sox -t 8svx - -t aiff -r 16000 -', '--')
  38. table['8svx'] = t
  39. t = pipes.Template()
  40. t.append('sox -t sndt - -t aiff -r 16000 -', '--')
  41. table['sndt'] = t
  42. t = pipes.Template()
  43. t.append('sox -t sndr - -t aiff -r 16000 -', '--')
  44. table['sndr'] = t
  45. uncompress = pipes.Template()
  46. uncompress.append('uncompress', '--')
  47.  
  48. class error(Exception):
  49.     pass
  50.  
  51.  
  52. def toaiff(filename):
  53.     temps = []
  54.     ret = None
  55.     
  56.     try:
  57.         ret = _toaiff(filename, temps)
  58.     finally:
  59.         for temp in temps[:]:
  60.             if temp != ret:
  61.                 
  62.                 try:
  63.                     os.unlink(temp)
  64.                 except os.error:
  65.                     pass
  66.  
  67.                 temps.remove(temp)
  68.                 continue
  69.         
  70.  
  71.     return ret
  72.  
  73.  
  74. def _toaiff(filename, temps):
  75.     if filename[-2:] == '.Z':
  76.         (fd, fname) = tempfile.mkstemp()
  77.         os.close(fd)
  78.         temps.append(fname)
  79.         sts = uncompress.copy(filename, fname)
  80.         if sts:
  81.             raise error, filename + ': uncompress failed'
  82.         sts
  83.     else:
  84.         fname = filename
  85.     
  86.     try:
  87.         ftype = sndhdr.whathdr(fname)
  88.         if ftype:
  89.             ftype = ftype[0]
  90.     except IOError:
  91.         msg = None
  92.         if type(msg) == type(()) and len(msg) == 2 and type(msg[0]) == type(0) and type(msg[1]) == type(''):
  93.             msg = msg[1]
  94.         
  95.         if type(msg) != type(''):
  96.             msg = repr(msg)
  97.         
  98.         raise error, filename + ': ' + msg
  99.  
  100.     if ftype == 'aiff':
  101.         return fname
  102.     if ftype is None or ftype not in table:
  103.         raise error, '%s: unsupported audio file type %r' % (filename, ftype)
  104.     ftype not in table
  105.     (fd, temp) = tempfile.mkstemp()
  106.     os.close(fd)
  107.     temps.append(temp)
  108.     sts = table[ftype].copy(fname, temp)
  109.     if sts:
  110.         raise error, filename + ': conversion to aiff failed'
  111.     sts
  112.     return temp
  113.  
  114.